package io.renren.controller;

import io.renren.common.utils.R;
import io.renren.service.business.AppBusinessService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author winson
 * @CREATE 11 23:53
 */
@RestController
@RequestMapping("/app")
@Api(tags="应用模块接口")
public class AppController {

    @Autowired
    private AppBusinessService appBusinessService;

    // 获取应用分类接口
    @GetMapping("/category/list")
    public R getCategoryList(){
        return R.ok().put( "data", appBusinessService.getCategoryList() );
    }

    // 获取应用栏目列表接口(全部栏目以及栏目下的应用)
    @GetMapping("/column/list")
    public R getColumnList(){
        return R.ok().put("data", appBusinessService.getColumnAppList() );
    }

    // 获取首页的应用列表接口
    @GetMapping("/index")
    public R index(){
        return R.ok().put("data", appBusinessService.getIndex() );
    }

    // 获取不同分类下的应用列表接口，带分页
    @GetMapping("/category/app/list")
    public R getCategoryAppList( Map<String,Object> params ){
        Integer page = (Integer) params.get( "page" );
        Integer categoryId = (Integer) params.get( "categoryId" );
        return R.ok().put("data", appBusinessService.getAppByCategory( page == null ? 1 :page, categoryId ));
    }


    // 获取不同栏目下的应用列表接口，带分页
    @GetMapping("/column/app/list")
    public R getColumnAppList( Map<String,Object> params ){
        Integer page = (Integer) params.get( "page" );
        Integer columnId = (Integer) params.get( "columnId" );
        return R.ok().put("data", appBusinessService.getAppByColumn( page == null ? 1 : page, columnId ));
    }

    // 获取应用详情接口
    @GetMapping("/detail")
    public R getAppDetail( Map<String,Object> params ){
        Integer appId = (Integer) params.get( "appId" );
        return R.ok().put("data", appBusinessService.getAppDetail( appId ));
    }

    // 应用评论接口
    @GetMapping("/evaluate")
    public R evaluateApp( Map<String,Object> params ){
        Integer appId = (Integer) params.get( "appId" );
        String comment = (String) params.get( "comment" );
        Integer userId = (Integer) params.get( "userId" );
        appBusinessService.evaluate( appId, userId, comment );
        return  R.ok();
    }

    // 获取应用评论列表接口，带分页
    @GetMapping("/evaluate/list")
    public R evaluateList( Map<String,Object> params ){
        Integer appId = (Integer) params.get( "appId" );
        Integer page = (Integer) params.get( "page" );
        return  R.ok().put("data", appBusinessService.getAppCommentList( page == null ? 1: page, appId ));
    }

}
